package com.mxchip.livestarmobile.mobile.ui.call

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.mxchip.livestarmobile.mobile.util.Log.MyLog

object ScreenRepository {


    private val mStreamingAVDevices = MutableLiveData<Set<AVDevice>>(linkedSetOf())


    fun addStreamingAVDevice(device: AVDevice) {
        val list = mStreamingAVDevices.value

        Log.e("AVRepository", "addStreamingAVDevice before list: $list")

        if (list is LinkedHashSet) {
            list.add(device)
        }

        Log.e("AVRepository", "addStreamingAVDevice after list: $list")
        mStreamingAVDevices.value = list
    }

    fun removeStreamingAVDevice(uid: String, deviceName: String) {

        val list = mStreamingAVDevices.value

        Log.e("AVRepository", "removeStreamingAVDevice before list: $list")

        if (list is LinkedHashSet) {
            list.removeIf {
                uid == it.uid && deviceName == it.deviceName
            }
        }

        MyLog.logD(MyLog.STREAMING_AV_DEVICE_MODEL,"VRepository::removeStreamingAVDevice $list")

        mStreamingAVDevices.value = list
    }
    val streamingAVDevices: LiveData<Set<AVDevice>>
        get() = mStreamingAVDevices

}